package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.CategoryService;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.entity.system.Category;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;

@RequestMapping(value = "/admin/product/category")
@RestController
@Tag(name = "种类")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @Operation(summary = "根据parentid获取下级节点")
    @GetMapping(value = "/findByParentId/{parentId}")
    public Result<List<Category>> findByParentId(@PathVariable Long parentId){
        List<Category> list = categoryService.findByParentId(parentId);
        return Result.OK(list);
    }

    @Operation(summary = "Excel形式导出数据")
    @GetMapping(value = "/exportData")
    public void exportData(HttpServletResponse response){
        categoryService.exportData(response);
    }

    @Operation(summary = "导入Excel形式数据")
    @PostMapping("importData")
    public Result importData(MultipartFile file) throws IOException {
        categoryService.importData(file);
        return Result.OK();
    }
}
